package com.newtouch.avmarketing.mgr.modules.avmarkrting.api;

import com.newtouch.avmarketing.mgr.modules.avmarkrting.entity.VideoInformation;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.model.Result;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.model.ResultCodes;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.service.DoubleAuditingService;
import com.newtouch.avmarketing.mgr.modules.avmarkrting.service.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags ="05 双录节点：视频上传")
@RestController
@RequestMapping(value = "/api/video")
public class UploadVideoController {
    @Autowired
    private DoubleAuditingService doubleAuditingService;
    @Autowired
    private FileUploadService fileUploadService;

    @ApiOperation("视频上传/生成双录审核数据")
    @PostMapping("/upload")
    public Result upload(@RequestParam(value = "file",required = false) MultipartFile file
            ,HttpServletRequest request
            ,@ApiParam("policyCode") @RequestParam String policyCode)throws Exception {
        Map<String, Object> map = fileUploadService.uploadFile(file, request, policyCode);
        if (map.size() != 0){
            return Result.of(ResultCodes.SUCCESS_CODE,map.get("message").toString(),map);
        }else {
            return Result.of(ResultCodes.ERROR_CODE,"上传视频失败");
        }
    }
    @ApiOperation("生成双录视频节点信息")
    @PostMapping("/updateVideoInfo")
    public Result updateVideoInfo(@ApiParam("policyCode") @RequestParam String policyCode,
                                  @ApiParam("policyCode") @RequestParam String endTime,
                                 @RequestBody List<VideoInformation> videoInformationList)throws Exception {
        Map<String, Object> map = fileUploadService.updateVideoInfo(policyCode,endTime,videoInformationList);
        if (map.size() != 0){
            return Result.of(ResultCodes.SUCCESS_CODE,map.get("message").toString(),map);
        }else {
            return Result.of(ResultCodes.ERROR_CODE,"生成失败");
        }
    }
//
//    @ApiOperation("生成双录视频节点信息id测试")
//    @PostMapping("/updateVideoInfoId/{policyCode}")
//    public Result updateVideoInfoId(@PathVariable String policyCode,
//                                 @RequestParam("idList") List<Long> idList)throws Exception {
//        Map<String, Object> map = fileUploadService.updateVideoInfoId(policyCode,idList);
//        if (map.size() != 0){
//            return Result.of(ResultCodes.SUCCESS_CODE,map.get("message").toString(),map);
//        }else {
//            return Result.of(ResultCodes.ERROR_CODE,"生成失败");
//        }
//    }
//
//
//    @ApiOperation("通过投保单号查询视频地址")
//    @PostMapping("/playVideo/{policyCode}")
//    public Result play(@PathVariable String policyCode)throws Exception {
//        DoubleAuditing byPolicyCode = doubleAuditingService.findByPolicyCode(policyCode);
//        if (byPolicyCode!=null){
//            String path = byPolicyCode.getVideoPath();
//            return Result.of(ResultCodes.SUCCESS_CODE,"查询成功",path);
//        }else {
//            return Result.of(ResultCodes.ERROR_CODE,"未查询到双录视频信息");
//        }
//    }

}
